<?php
	include_once 'BaseDAO.php';
	include_once '../object/Project.php';
	include_once '../util/Mapping.php';
	class Project_DAO extends BaseDAO
	{
		public function __construct(){
			
		}
                public function getList_Projects($cate_id,$offset,$limit){

			$listProject= array();
			$sql = "Select id,pro_name,pro_description,cate_id from projects where cate_id =".$cate_id." order by id ASC";
//		 	$sql .= " limit ".$offset.", ".$limit;
			$rs = parent::query($sql);
			while($row = $rs->fetch(PDO::FETCH_OBJ))
			{
				$project=new Project();
				Mapping::mapList_Projects($row,$project);
				array_push($listProject,$project);
			}
			return $listProject;

		}
		public function getProject_Detail($id)
		{

			$sql = "Select * from projects Where id=".$id;
			$rs = parent::query($sql);
			while($row = $rs->fetch(PDO::FETCH_OBJ))
			{
				$project=new Project();
				Mapping::mapList_Projects($row,$project);
			}
			return $project;

		}
                public function getProject_Descript($id)
		{

			$sql = "Select pro_description from projects Where id=".$id;
			$rs = parent::query($sql);
			$row = $rs->fetch(PDO::FETCH_OBJ);
			return $row->pro_description;

		}
		public function getRows(){
			$sql = "select count(*) from projects";
			$rs = parent::query($sql);
			$rows = $rs->fetch(PDO::FETCH_OBJ);
			return $rows;
		}
		public function insert_Project($project){
                        $sql = "INSERT INTO projects(pro_name,pro_description,cate_id)
					 VALUES(
                                            '".$project->getPro_Name()."',
                                            '".$project->getPro_Description()."',
                                            '".$project->getCate_id()."')";
                        parent::execute($sql);
		}
		public function update_Project($project)
		{
                        $pro_image = $project->getPro_Image();
				$sql = "Update projects set
					pro_name='".$project->getPro_name()."',
                                        pro_description='".$project->getPro_Description()."'";
                                $sql .= "where id='".$project->getID()."'";
			parent::execute($sql);			
		}
		public function delete_Project($id)
		{
			$sql = "Delete from projects where id='".$id."'";
			parent::execute($sql);			
		}
	}
?>